var gulp        = require('gulp');
var browserSync = require('browser-sync').create();
var less = require('gulp-less');
var path = require('path');
var spritesmith = require('gulp.spritesmith');

// 生成合并图片
gulp.task('sprite', function () {
  var spriteData = gulp.src('./styles/images/icon/*.png').pipe(spritesmith({
    imgName: 'sprite-icon.png',
    cssName: 'sprite-icon.css'
  }));
  return spriteData.pipe(gulp.dest('./styles/'));
});

gulp.task('spriteWX', function () {
  var spriteData = gulp.src('./styles/images/wx-icon/*.png').pipe(spritesmith({
    imgName: 'sprite-wxicon.png',
    cssName: 'sprite-wxicon.css'
  }));
  return spriteData.pipe(gulp.dest('./styles/'));
});

gulp.task('less', function () {
  return gulp.src('./styles/**/*.less')
    .pipe(less({
      paths: [ path.join(__dirname, 'less', 'includes') ]
    }))
    .pipe(gulp.dest('./styles'))
    .pipe(browserSync.stream());
});

// Static Server + watching scss/html files
gulp.task('serve', ['less'], function() {

    browserSync.init({
        server: "./"
    });

    gulp.watch("./styles/*.less", ['less']);
    gulp.watch("./*.html").on('change', browserSync.reload);
});


gulp.task('default', ['serve']);
